home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
basic
/
CNKI.lha
/
CNKI
/
CNKI.ascii
< prev
next >
Wrap
Text File
|
1999-04-03
|
4KB
|
183 lines
;************************************
;* CNKI file format by Chris Deeney *
;* 3-4-1999 *
;************************************
CNkIvEr$="CNKI V1.0 By Chris Deeney"
;***********************************
;*-*- Error codes for LoadCNK:- -*-*
;***********************************
;#0 = File doesn't exist / Can't read file!
;#1 = Not a CNKI file format!
;#2 = File is corrupt!
;#3 = Can't allocate enough fast ram!
;#4 = Illegal parameters!
Function LoadCNK{im,dir$}
If im<0 Then Function Return 4
If dir$="" Then Function Return 4
ecode=-1
If ReadFile(0,dir$)
FileInput 0
;;*** check header ***
FileSeek 0,0
i$=Inkey$(8)
If i$="FORMCNKI"
;is the file compressed?
FileSeek 0,20
i$=Inkey$(4)
If i$=" " OR i$="COMP"
If i$="COMP" Then compressed=-1
;get number of frames
FileSeek 0,8
i$=Inkey$(4)
h$=""
f=Asc(Mid$(i$,1,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,2,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,3,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,4,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
shaps=Hex#(h$)
If shaps=0 Then PopInput:CloseFile 0:Function Return 2
;get shape width
FileSeek 0,12
i$=Inkey$(4)
h$=""
f=Asc(Mid$(i$,1,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,2,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,3,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,4,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
sw=Hex#(h$)
If sw=0 Then PopInput:CloseFile 0:Function Return 2
;get shape height
FileSeek 0,16
i$=Inkey$(4)
h$=""
f=Asc(Mid$(i$,1,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,2,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,3,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,4,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
sh=Hex#(h$)
If sh=0 Then PopInput:CloseFile 0:Function Return 2
;;******
; allocate some memory to store the uncompressed file
size.l=sw*sh*shaps
addy.l=AllocMem(size.l,1LSL2) ;1LSL2=fastram
If addy.l=0 Then PopInput:CloseFile 0:Function Return 3
;;*** if the file is compressed ***
If compressed=-1
;** decompress the file into addy **
z.l=24 ; read position after header
dp.l=0 ; addy offset in mem
Repeat
FileSeek 0,z.l
i$=Inkey$(1)
cl=Asc(i$)
z.l+1
FileSeek 0,z.l
i$=Inkey$(1)
c=Asc(i$)
;c$=Chr$(c)
For n=1 To cl
Poke.b addy.l+dp.l,c
dp.l+1
Next
z.l+1
Until Eof(0)
;**
Else FileSeek 0,24:ReadMem 0,addy.l,size.l ;*Else load it straight into addy
End If
;;******
fok=-1
Else ecode=2
End If
Else ecode=1
End If
PopInput
CloseFile 0
Else ecode=0
End If
;;*** if every thing whent ok, then decode images ***
If fok=-1
size.l=sw*sh; work out size for 1 frame
faddy.l=addy.l
;** make some shapes! **
For n=0 To shaps-1
;allocate some memory for a shape
saddy.l=AllocMem(size.l+16,1LSL2) ;1LSL2=fastram
If saddy.l=0 Then Function Return 3
;work out 16 byte offset
taddy.l=Int(saddy.l/16):taddy.l*16
If taddy.l<saddy.l Then taddy.l+16
faddy.l=addy.l+(n*size.l)
For z.l=0 To size.l-1
col=Asc(Peeks$(faddy.l+z.l,1))
If col=255 Then col=Asc(Peeks$(MShapePtr(im-1)+z.l,1))
Poke.b taddy.l+z.l,col
Next
MCludgeShape im,sw,sh,taddy.l
MMakeCookie im
im+1
Next
;**
End If
;;******
Function Return ecode
End Function
;** returns number of frames in a CNKI file
Function.w CnkFrames{dir$}
If ReadFile(0,dir$)
FileInput 0
;;*** check header ***
FileSeek 0,0
i$=Inkey$(8)
If i$="FORMCNKI"
;get number of frames
FileSeek 0,8
i$=Inkey$(4)
h$=""
f=Asc(Mid$(i$,1,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,2,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,3,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
f=Asc(Mid$(i$,4,1)):f$=Hex$(f):h$+Mid$(f$,7,2)
shaps=Hex#(h$)
If shaps=0 Then PopInput:CloseFile 0:Function Return -1
Else PopInput:CloseFile 0:Function Return -1
End If
PopInput
CloseFile 0
Else Function Return -1
End If
Function Return shaps
End Function